package cc.tutorial.aop.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * Created by rico on 2018/5/8.
 */
@Aspect
@Component
public class OperationLogAspect {
    private static final Logger logger = LoggerFactory.getLogger(OperationLogAspect.class);

    /**
     * 定义日志切入点
     */
    @Pointcut(value = "@annotation(cc.tutorial.aop.annotation.OperateLogAnnotation)")
    public void serviceAspect() {
        logger.info("##OperationLogAspect.handleServiceLog...");
    }

    /**
     * 后置通知 用于拦截service层记录用户的操作
     * @param joinPoint
     */
    @After("serviceAspect()")
    public void doAfter(JoinPoint joinPoint) {
        logger.info("##OperationLogAspect.doAfter...");
    }

    /**
     * 后置通知 用于拦截service层记录用户的操作
     * @param joinPoint
     */
    @Before("serviceAspect()")
    public void doBefore(JoinPoint joinPoint) {
        logger.info("##OperationLogAspect.doBefore...");
    }

    @AfterThrowing(pointcut = "serviceAspect()", throwing = "e")
    public void doAfterThrowing(JoinPoint joinPoint, Throwable e) {
        logger.info("##OperationLogAspect.doAfterThrowing...");
    }

}
